package com.kgc.server.controller;

import com.kgc.server.pojo.EasyBuyNews;
import com.kgc.server.pojo.Page;
import com.kgc.server.service.IndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private IndexService indexService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("getEasybuy_product_categoryList")
    @ResponseBody
    @CrossOrigin
    public List getEasybuy_product_categoryList(){
        logger.info("IndexController getEasybuy_product_categoryList start");
        List list = indexService.getEasybuy_product_categoryList();
        logger.info("IndexController getEasybuy_product_categoryList list:"+list);
        return list;
    }

    @RequestMapping("getNewsList")
    @ResponseBody
    @CrossOrigin
    public List getNewsList(){
        logger.info("IndexController getNewsList start");
        List list = indexService.getNewsList();
        logger.info("IndexController getNewsList list:"+list);
        return list;
    }

    @RequestMapping("getinformationListFy")
    @ResponseBody
    @CrossOrigin
    public List getinformationListFy(Page page){
        logger.info("IndexController getNewsList page:"+page);
        List list = indexService.getinformationListFy(page);
        list.add(page);
        logger.info("IndexController getNewsList page:"+page+",list:"+list);
        return list;
    }

    @RequestMapping("delInformationListById")
    @ResponseBody
    @CrossOrigin
    public boolean delInformationListById(int id){
        logger.info("IndexController delInformationListById id:"+id);
        int num = indexService.delInformationListById(id);
        logger.info("IndexController delInformationListById id:"+id+",num:"+num);
        if( num > 0 ){
            return true;
        }
        return false;
    }

    @RequestMapping("getInformation")
    @ResponseBody
    @CrossOrigin
    public List getInformation(int id){
        logger.info("IndexController getInformation id:"+id);
        List list = indexService.getInformation(id);
        logger.info("IndexController getInformation id:"+id+",list:"+list);
        return list;
    }

    @RequestMapping("updataInformationById")
    @ResponseBody
    @CrossOrigin
    public boolean updataInformationById(EasyBuyNews easyBuyNews){
        logger.info("IndexController updataInformationById easyBuyNews:"+easyBuyNews);
        int num = indexService.updataInformationById(easyBuyNews);
        logger.info("IndexController updataInformationById easyBuyNews:"+easyBuyNews+",num:"+num);
        if( num > 0 ){
            return true;
        }
        return false;
    }
}
